import 'package:flutter/material.dart';
import 'package:lib_module_manager/module_manager/page_lifecycle.dart';
import 'package:lib_module_manager/module_manager/widgets/page_widget.dart';
import 'package:lib_module_manager/module_manager/page.dart' as module_manager;

abstract class PageWidgetState<T extends PageWidget> extends State<T>
    with PageLifecycle {
  module_manager.Page get page => widget.page;

  @override
  void initState() {
    super.initState();

    registerPageLifecycle(channel: page.channel);
  }

  @override
  void dispose() {
    super.dispose();

    onPageDispose();
  }

  @override
  void onPageDispose() {
    super.onPageDispose();

    widget.page.module.removePage(type: widget.page.type, id: widget.page.id);
  }
}
